//
//  AppDelegate.m
//  International_Hospital
//
//  Created by LiYiLin on 16/7/4.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "AppDelegate.h"
#import "JASidePanelController.h"
#import "Home_ViewController.h"
#import "Left_ViewController.h"
#import "Base_NavController.h"
#import "GuideCollectionVC.h"


#import<ShareSDK/ShareSDK.h>

#import"WXApi.h"

#import<ShareSDKConnector/ShareSDKConnector.h>

#import<TencentOpenAPI/QQApiInterface.h>

#import<TencentOpenAPI/TencentOAuth.h>

#import"WeiboSDK.h"

@interface AppDelegate ()<WXApiDelegate>

//侧滑的控制器
@property (nonatomic, strong) JASidePanelController * JASide_ViewController;

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //设置window窗口
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    [self setController];
    
    
    
    return YES;
}

#pragma mark -
#pragma mark  设置控制器
-(void)setController{
    //根据APP版本判断是不是第一次启动
    //1.获取当前APP的版本号
    NSString *current_ver =[NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    
    //2.从偏好设置中获取上一次记录的app的版本号, 假设上次版本号记录到了 last_ver 中
    NSUserDefaults *userDe = [NSUserDefaults standardUserDefaults];
    
    //获取上一次的版本号
    NSString *last_ver = [userDe objectForKey:@"last_ver"];
    
    //判断两个版本是否相同
    if ([current_ver isEqualToString:last_ver]) {
        
        //实例化 JASidePanelController
        self.JASide_ViewController = [[JASidePanelController alloc] init];
        
        //实例化 左侧 Left_ViewController
        self.JASide_ViewController.leftPanel = [[Left_ViewController alloc] init];
        
        //实例化 右侧 Home_ViewController
        Home_ViewController * home_VC = [[Home_ViewController alloc] init];
        
        self.JASide_ViewController.centerPanel = [[Base_NavController alloc] initWithRootViewController:home_VC];
        
        self.window.rootViewController = self.JASide_ViewController;
        
        //让window成为主window并且显示
        [self.window makeKeyAndVisible];
        
        
    }else{
        
        //创建新特性控制器
        GuideCollectionVC * guideCollectionVC = [[GuideCollectionVC alloc]init];
        
        self.window.rootViewController = guideCollectionVC;
        
        //状态栏隐藏
        [UIApplication sharedApplication].statusBarHidden = YES;
        
        //让window成为主window并且显示
        [self.window makeKeyAndVisible];
        
        //把当前的App的版本号记录到偏好设置中
        
        //这个必须用字符串
        //[userDe setObject:current_ver forKey:last_ver];
        
        [userDe setObject:current_ver forKey:@"last_ver"];
        
        //同步
        [userDe synchronize];
        
    }
    
    [self shareWithWeibo];
    

}


- (void)shareWithWeibo {
    
    
    [ShareSDK registerApp:@"AppKey" activePlatforms:
     @[@(SSDKPlatformSubTypeWechatSession),@(SSDKPlatformSubTypeWechatTimeline),@(SSDKPlatformSubTypeWechatFav),@(SSDKPlatformTypeSinaWeibo), @(SSDKPlatformTypeQQ),@(SSDKPlatformTypeYinXiang),@(SSDKPlatformSubTypeQZone), @(SSDKPlatformTypeCopy)] onImport:^(SSDKPlatformType platformType) {
         
         switch (platformType) {
                 
             case SSDKPlatformTypeWechat: {
                 
                 [ShareSDKConnector connectWeChat:[WXApi class]];
                 
             }
                 
                 break;
                 
             case SSDKPlatformTypeQQ: {
                 
                 [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
                 
             }
                 
                 break;
                 
             default:
                 
                 break;
                 
         }
         
     } onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo) {
         
         switch (platformType) {
                 
             case SSDKPlatformTypeSinaWeibo: {
                 
                 [appInfo SSDKSetupSinaWeiboByAppKey:@"670315478" appSecret:@"22e8dc19daf69fc59cf3010ad4dd5fc0" redirectUri:@"https://api.weibo.com/oauth2/default.html" authType:SSDKAuthTypeBoth];
                 
             }
                 
                 break;
                 
             case SSDKPlatformTypeWechat: {
                 
                 [appInfo SSDKSetupWeChatByAppId:@"微信appkey" appSecret:@"微信apply对应的密码"];
                 
             }
                 
                 break;
                 
             case SSDKPlatformTypeQQ: {
                 
                 [appInfo SSDKSetupQQByAppId:@"QQappID" appKey:@"QQappkey" authType:SSDKAuthTypeSSO];
                 
             }
                 
                 break;
                 
             case SSDKPlatformTypeYinXiang:
                 
                 [appInfo SSDKSetupEvernoteByConsumerKey:@"印象笔记appkey" consumerSecret:@"印象笔记appkey对应的密码" sandbox:NO];
                 
                 break;
                 
             default:
                 
                 break;
                 
         }
         
     }];
    

}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
